package cn.ycbjie.ycaudioplayer.ui.study.ui.fragment;

import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.pedaily.yc.ycdialoglib.customToast.ToastUtil;
import com.synjones.minnovate.frame.basesdk.http.SynHttp;
import com.synjones.minnovate.frame.basesdk.http.SynSchedulersTranfs;
import com.synjones.minnovate.frame.basesdk.http.exception.AbsRxSubscriber;
import com.synjones.minnovate.frame.basesdk.http.exception.ApiException;
import com.synjones.minnovate.frame.basesdk.log.SynLog;
import com.yc.cn.ycbannerlib.first.BannerView;
import com.yc.cn.ycbannerlib.first.util.SizeUtil;

import org.json.JSONArray;
import org.json.JSONObject;
import org.yczbj.ycrefreshviewlib.YCRefreshView;
import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.item.RecycleViewItemLine;
import org.yczbj.ycrefreshviewlib.item.SpaceViewItemLine;
import org.yczbj.ycrefreshviewlib.viewHolder.BaseViewHolder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import cn.ycbjie.ycaudioplayer.R;
import cn.ycbjie.ycaudioplayer.api.http.OnLineMusicModel;
import cn.ycbjie.ycaudioplayer.base.BaseFragment;
import cn.ycbjie.ycaudioplayer.mybean.myhomemaibean;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.ContentAcitvity;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.MainActivity;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.MyPlayerActivity;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.NestScrollingActivity;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.NestScrollingActivitynew;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.adapter.RecyclerBaseAdapter3;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.iapiserver.iapi;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.mybeans.MyPlayerlistBean;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.mybeans.MyhomeIconBean;
import cn.ycbjie.ycaudioplayer.ui.main.MainHomeActivity;
import cn.ycbjie.ycaudioplayer.ui.music.local.model.AudioMusic;
import cn.ycbjie.ycaudioplayer.ui.music.onLine.model.bean.OnlineMusicList;
import cn.ycbjie.ycaudioplayer.ui.study.model.VideoPlayerFavorite;
import cn.ycbjie.ycaudioplayer.ui.study.ui.adapter.BannerPagerAdapter;
import cn.ycbjie.ycaudioplayer.ui.study.ui.adapter.NarrowImageAdapter;
import cn.ycbjie.ycaudioplayer.ui.study.ui.adapter.StudyAdapter;
import cn.ycbjie.ycaudioplayer.util.binding.Bind;
import cn.ycbjie.ycaudioplayer.util.other.BitmapHelper;
import cn.ycbjie.ycaudioplayer.util.other.GlideUtil;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import static cn.ycbjie.ycaudioplayer.newpack.linkagescroll.config.MyConfig.baseURL;

/**
 * Created by yc on 2018/1/24.
 */

public class StudyFragment extends BaseFragment {

    @BindView(R.id.recyclerView)
    YCRefreshView recyclerView;
    private MainHomeActivity activity;
    private StudyAdapter adapter;


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        activity = (MainHomeActivity) context;
    }


    @Override
    public void onDetach() {
        super.onDetach();
        activity = null;
    }


    @Override
    public int getContentView() {
        return R.layout.base_easy_recycle;
    }


    @Override
    public void initView() {
        initYCRefreshView();
    }


    @Override
    public void initListener() {

    }


    @Override
    public void initData() {
        getdatas();
//        ArrayList<myhomemaibean.DataBean.ResourcesBean> resourcesBeans = getdatas();
//        UserAdapter adapter = new UserAdapter(getContext(), R.layout.item_study_news,
//                R.id.tv_home_sub_num,resourcesBeans);
//        recyclerView.setAdapter(adapter);
//        List<String> data = new ArrayList<>();
//        for(int a=0 ; a<10 ; a++){
//            data.add("假数据"+a);
//        }
//        adapter.addAll(data);
//        adapter.notifyDataSetChanged();
    }

    private void getdatas() {
////        final List<myhomemaibean.DataBean.ResourcesBean>[] resourcesBeanss;
//        final List<myhomemaibean.DataBean.ResourcesBean> resourcesBeanss = {new ArrayList<myhomemaibean.DataBean.ResourcesBean>()};

//        final List<myhomemaibean.DataBean.ResourcesBean>[] data = new List<myhomemaibean.DataBean.ResourcesBean>[1];
//        final myhomemaibean[] myhomemaibeantsstt = {null};
        SynHttp.getInstance().getApi(baseURL, iapi.class).gethome()
                .compose(SynSchedulersTranfs.<myhomemaibean>schedulersTransformer())
                .subscribe(new AbsRxSubscriber<myhomemaibean>() {
                    @Override
                    public void onRxError(ApiException ex) {
                        SynLog.file(ex.getDisplayMessage());
                    }


                    public void onNext(final myhomemaibean myhomemaibeanbean) {


                                recyclerView.setAdapter(adapter);
//        List<String> data = new ArrayList<>();
//        for(int a=0 ; a<10 ; a++){
//            data.add("假数据"+a);
//        }
        adapter.addAll(myhomemaibeanbean.getData().get(4).getResources());
        adapter.notifyDataSetChanged();
        adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                myhomemaibean.DataBean.ResourcesBean rs = adapter.getAllData().get(position);
                Intent intent= new Intent();
                intent.setClass(getActivity(), NestScrollingActivity.class);

                intent.putExtra("id",rs.getId());
                intent.putExtra("picurl",rs.getCover());
                intent.putExtra("title",rs.getTitle());
                intent.putExtra("created",rs.get_created_at());
                try {
                    intent.putExtra("summary", rs.getSummary().toString());
                }
                catch (Exception ex)
                {
                    ex.printStackTrace();
                }
                getActivity().startActivity(intent);
                ToastUtils.showShort(rs.getTitle()+"点击呢！！！");
            }
        });
                        initHorizontalView(myhomemaibeanbean.getData().get(3).getResources());
//                        List<myhomemaibean.DataBean.ResourcesBean> resourcesBeans = myhomemaibeanbean.getData().get(0).getResources();
//                        UserAdapter adapters = new UserAdapter(getActivity(), R.layout.item_study_news,
//                                R.id.tv_home_sub_num,resourcesBeans);
//                        recyclerView.setAdapter(adapters);

                        //                        List<myhomemaibean.DataBean.ResourcesBean> resourcesBeanss = myhomemaibeanbean.getData().get(0).getResources();
////                        return; resourcesBeanss[0][0];
//                        data[0] = resourcesBeanss;
//                        return resourcesBeanss;
                        //                        try {
//                            JSONObject obj = new JSONObject(weatherInfoBean.toString());
//                            String code = obj.getString("code");
//                            String data = obj.getString("data");
//
//                            JSONObject objer = new JSONObject(data);
//                            JSONArray jsonArray = objer.getJSONArray("data");
//                            String dataer = objer.getString("data");
//                            int total = Integer.parseInt(objer.getString("total"));
//                            int limit = 100;//Integer.parseInt(objer.getString("limit"));
//                            int pp = total / limit + 1;
//                            Gson gson = new Gson();
//                            JsonParser parser = new JsonParser();
//                            JsonArray Jarray = parser.parse(dataer).getAsJsonArray();
//                            for (JsonElement objel : Jarray) {
//                                MyPlayerlistBean cse = gson.fromJson(objel, MyPlayerlistBean.class);
//                                lcs.add(cse);
//
//                            }
//                            if (isfirst) {
//                                recyclerBaseAdapter = new RecyclerBaseAdapter3(getActivity(), lcs);
//
////                                recyclerBaseAdapter = new RecyclerBaseAdapter3(getActivity(), dataList);
//                                recyclerBaseAdapter.setOnItemClickListener(new RecyclerBaseAdapter3.OnItemClickListener() {
//                                    @Override
//                                    public void onItemClick(View view, int position) {
//                                        recyclerBaseAdapter.setDefSelect(position);
//                                        TextView tv = view.findViewById(R.id.tv_playerlist_id);
//                                        TextView tvpic = view.findViewById(R.id.tv_playerlist_pic);
//                                        String ids = tv.getText().toString();
//                                        String pic = tvpic.getText().toString();
//                                        OnlineMusicList.OnlineMusic onlineMusic = new OnlineMusicList.OnlineMusic();
//                                        onlineMusic.setTitle("测试数据数据");
//                                        onlineMusic.setSong_id(ids);
//                                        onlineMusic.setPic_big(pic);
//                                        List<AudioMusic> ls = new ArrayList<AudioMusic>();
//
////                                        AudioMusic audioMusic = new AudioMusic();
////                                        audioMusic.setArtist("ccc");
////                                        audioMusic.setCoverPath(pic);
////                                        audioMusic.setPath("http://fdfs.xmcdn.com/group19/M00/3B/21/wKgJK1ePRjLwvXl0AAy74JiGcgw431.mp3");
////                                       ls.add(audioMusic);
////                                       getPlayService().play(audioMusic,position);
//                                        playbyid(position, true);
////                                     playMusic(onlineMusic);
//                                        Toast.makeText(getActivity(), "click " + position + "-" + ids, Toast.LENGTH_SHORT).show();
//                                    }
//                                });
////                                recyclerBaseAdapter.setOnItemLongClickListener(new RecyclerBaseAdapter3.OnItemLongClickListener() {
////                                    @Override
////                                    public void onItemLongClick(View view, int position) {
////                                        Toast.makeText(getActivity(),"long click "+position,Toast.LENGTH_SHORT).show();
////                                    }
////                                });
//                                listItemRecycler.setAdapter(recyclerBaseAdapter);
//                            } else {
////                                //添加数据到列表的底部
////
////                                if(pp<Integer.parseInt(page))
////                                {
////                                    //没有加载更多了
////                                    adapterlist.changeMoreState(adapterlist.NO_LOAD_MORE);
////                                }
////
////                                else
////                                {
////                                    adapterlist.addFootItem(lcs);
////
////                                    //设置回到上拉加载状态
////                                    adapterlist.changeMoreState(adapterlist.PULLUP_LOAD_MORE);
////
////
////                                    Toast.makeText(mcontext, "上拉更新了" + lcs.size() + "条数据", Toast.LENGTH_SHORT).show();
////                                }
//                            }
////                            if (adapterlist==null) {
////                                dropListView = (DropListView) findViewById(R.id.list_view_id);
////                                lv.setInterface(test_musicplayer.this);//设置回调接口
////                            adapterlist = new MyFinderAdapter(mcontext, lcs);
////                                lv.setAdapter(adapterlist);
////                            }else {
////                                adapterlist.onDateChange();
////                            }
//
////                            adapterlist = new MyAdapter(test_musicplayer.this, lcs);
////                            lv.setInterface(test_musicplayer.this);//设置回调接口
//
////                            ref_finderlist.setAdapter(adapterlist);
//                        } catch (Exception ex) {
//                            ex.printStackTrace();
//                        }
                        SynLog.file("String----->" + myhomemaibeanbean.toString());
                    }
                });


//        return null;
    }


    private void initYCRefreshView() {
        recyclerView.setLayoutManager(new LinearLayoutManager(activity));
        final RecycleViewItemLine line = new RecycleViewItemLine(activity, LinearLayout.HORIZONTAL,
                SizeUtils.dp2px(1), Color.parseColor("#f5f5f7"));
        recyclerView.addItemDecoration(line);
        adapter = new StudyAdapter(activity);
        recyclerView.setAdapter(adapter);
        addHeader();
        recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                SwipeRefreshLayout swipeToRefresh = recyclerView.getSwipeToRefresh();
                if(swipeToRefresh.isRefreshing()){
                    recyclerView.setRefreshing(false);
                }
            }
        });
    }


    /**
     * 添加头部
     */
    private void addHeader() {
        adapter.removeAllHeader();
        initTopHeaderView();
        initHeaderButton();
        initHeaderTitle();
//        initVideoContentView();//列表
        initFooterTitle();//猜你喜欢

    }

    private void initTopHeaderView() {
        final ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("http://cdn1.hkrstore.com/topics/12102018/jphnqyrjzxv8.jpg");
        arrayList.add("http://cdn1.hkrstore.com/topics/12132018/jply8p3escqq.png");
//        arrayList.add("http://bpic.wotucdn.com/11/66/23/55bOOOPIC3c_1024.jpg!/fw/780/quality/90/unsharp/true/compress/true/watermark/url/L2xvZ28ud2F0ZXIudjIucG5n/repeat/true");
//        arrayList.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1505470629546&di=194a9a92bfcb7754c5e4d19ff1515355&imgtype=0&src=http%3A%2F%2Fpics.jiancai.com%2Fimgextra%2Fimg01%2F656928666%2Fi1%2FT2_IffXdxaXXXXXXXX_%2521%2521656928666.jpg");
        adapter.addHeader(new RecyclerArrayAdapter.ItemView() {
            @Override
            public View onCreateView(ViewGroup parent) {
                return LayoutInflater.from(activity).inflate(R.layout.head_audio_banner, parent, false);
            }


            @Override
            public void onBindView(View headerView) {
                // 绑定数据
                BannerView mBanner = (BannerView) headerView.findViewById(R.id.banner);
                mBanner.setHintGravity(1);
                mBanner.setAnimationDuration(1000);
                mBanner.setPlayDelay(2000);
                mBanner.setHintPadding(0,SizeUtil.dip2px(activity,10),0, SizeUtil.dip2px(activity,10));
                mBanner.setAdapter(new BannerPagerAdapter(activity, arrayList));
            }
        });
    }


    private void initHeaderButton() {
       gethomeicon();

    }

    public void intview(GridView gridView,String[] name,String[] imageres)
    {

//                final String[] name = {"我的1","我的2","我的3","我的4","我的5","我的6","我的7"};
//        String[] imageres={"http://cdn1.hkrstore.com/topics/11132018/jofmk6qlda19.png","http://cdn1.hkrstore.com/topics/11132018/jofmk6qlda19.png","http://cdn1.hkrstore.com/topics/11132018/jofmk6qlda19.png","http://cdn1.hkrstore.com/topics/11132018/jofmk6qlda19.png","http://cdn1.hkrstore.com/topics/11132018/jofmk6qlda19.png","http://cdn1.hkrstore.com/topics/11132018/jofmk6qlda19.png"};
        //生成动态数组，并且转入数据
//        ArrayList<HashMap<String ,Object>> listItemArrayList=new ArrayList<HashMap<String,Object>>();
//        for(int i=0; i<imageres.length; i++){
//            HashMap<String, Object> map=new HashMap<String,Object>();
//            map.put("itemImage", imageres[i]);
////            map.put("itemText", name[i]);
//            listItemArrayList.add(map);
//        }


//下面对GridView进行加载
//下面的list是保存我们的图片组URL的
        ArrayList<HashMap<String,String>> list=new ArrayList<>();
        for(int i=0;i<imageres.length;i++) {
//单个的Map保存我们的URL
            HashMap<String, String> map = new HashMap<>();
            map.put("ItemImage", imageres[i]);
            map.put("itemText", name[i]);
            list.add(map);
        }



        //下面是SimpleAdapter的构建过程（参数依次是：1：上下文，2：数据源，3：子项布局，4：我们的子项布局的键值对的键 5：子项布局中键值对的值）
        SimpleAdapter adapter = new SimpleAdapter(getContext(),list,R.layout.home_gridview_item,new String[]{"ItemImage","itemText"}, new int[]{R.id.txt_shoukuan,R.id.txt_shoukuan});
//判断是否为我们要处理的对象,在这里adapter自动为子项赋值

        adapter.setViewBinder(new SimpleAdapter.ViewBinder(){

                                  public boolean setViewValue(View view, Object data,
                                                              String textRepresentation)
                                  {
//                                      ArrayList<HashMap<String,String>> listsssss = (ArrayList<HashMap<String,String>>) data;
//                                      HashMap<String ,Object> ls =(HashMap<String ,Object>) data;
//                                      ArrayList<HashMap<String ,Object>>  ls=(ArrayList<HashMap<String ,Object>> ) data;
//ls.get(get)
//                                      TextView tv=(TextView)
//                                      if(view instanceof ImageView){
//                                           ImageView iv = (ImageView)view;
////Log.e("AAAAAA", ls.get("itemImage").toString());
////                                          GlideUtil.GlideWithPlaceHolder(getContext(), data.toString()).into(iv);
////给子项布局加个点击事件
//
////                                          SimpleTarget<Drawable> simpleTarget = new SimpleTarget<Drawable>() {
////                                              @Override
////                                              public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
////                                                  //imageView.setImageDrawable(resource);
////                                                  iv.setBackground(resource);
////                                              }
////                                          };
//
////                                          Glide.with(getContext()).load("http://img.zcool.cn/community/01f9ea56e282836ac72531cbe0233b.jpg@2o.jpg").into(new SimpleTarget<Drawable>() {
////                                              @Override
////                                              public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
////                                                  iv.setBackground(resource);
////                                              }
////                                          });
////
////                                          Glide.with(getContext())
////                                                  .load("http://img.zcool.cn/community/01f9ea56e282836ac72531cbe0233b.jpg@2o.jpg")
////                                                  .into(simpleTarget);
//
                                      view.setOnClickListener(new View.OnClickListener(){
                                              @Override
                                              public void onClick(View v){

//                                                  Intent intent = new Intent();
//                                                  intent.setClass(getContext(), ContentAcitvity.class);
//                                                  startActivity(intent);
                                                  Toast.makeText(getContext(), "image"+1, Toast.LENGTH_SHORT).show();
                                              }
                                          });
//                                          if(view instanceof TextView)
//                                          {
                                              final TextView tx = (TextView)view;
if(data.toString().startsWith("http")) {
//tx.setText(((ArrayList<HashMap<String,String>>) data).get(0).get("itemText"));
//                                              Glide.with(getContext()).load("http://img.zcool.cn/community/01f9ea56e282836ac72531cbe0233b.jpg@2o.jpg").into(new SimpleTarget<Drawable>() {
//                                              @Override
//                                              public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
//                                                  iv.setBackground(resource);
//                                              }
//                                          });
    SimpleTarget<Drawable> simpleTarget = new SimpleTarget<Drawable>() {
        @Override
        public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
            //imageView.setImageDrawable(resource);
//                                                  resource.setBounds(null,null,100,100);
            resource.setBounds(0, 0, 36, 36);
            Drawable dr = resource;
            dr.setBounds(0, 0, dr.getMinimumWidth(), dr.getMinimumHeight());
            tx.setCompoundDrawablesWithIntrinsicBounds(null, dr, null, null);

//                                                  tx.setCompoundDrawablesWithIntrinsicBounds(tx.getCompoundDrawables()[0],resource,tx.getCompoundDrawables()[2],tx.getCompoundDrawables()[0]);

            Log.e("aaaaaaaaaaaaaaaaaaa", "ddddddddddddddddddddddddd");
        }
    };
    Glide.with(getContext())
            .load(data.toString())
            .into(simpleTarget);
//                                          }
}
else
{
    tx.setText(data.toString());
}

                                          return true;
//                                      }else
//                                          return false;
                                  }




//
////        GridView gridView;
////        View view = getActivity().findViewById(R.layout.head_audio_button);
//        final String[] name = {"我的","我的","我的","我的","我的","我的","我的"};
//        String[] imageres={"http://cdn1.hkrstore.com/topics/11132018/jofmk6qlda19.png","http://cdn1.hkrstore.com/topics/11132018/jofmk6qlda19.png","http://cdn1.hkrstore.com/topics/11132018/jofmk6qlda19.png","http://cdn1.hkrstore.com/topics/11132018/jofmk6qlda19.png","http://cdn1.hkrstore.com/topics/11132018/jofmk6qlda19.png","http://cdn1.hkrstore.com/topics/11132018/jofmk6qlda19.png"};
//        //生成动态数组，并且转入数据
//        ArrayList<HashMap<String ,Object>> listItemArrayList=new ArrayList<HashMap<String,Object>>();
//        for(int i=0; i<imageres.length; i++){
//            HashMap<String, Object> map=new HashMap<String,Object>();
//            map.put("itemImage", BitmapHelper.getBitmap(imageres[i]));
//            map.put("itemText", name[i]);
//            listItemArrayList.add(map);
//        }
//        //生成适配器的ImageItem 与动态数组的元素相对应
//        SimpleAdapter saImageItems = new SimpleAdapter(getActivity(),
//                listItemArrayList,//数据来源
//                R.layout.home_gridview_item,//item的XML
//
//                //动态数组与ImageItem对应的子项
//                new String[]{"itemImage", "itemText"},
//
//                //ImageItem的XML文件里面的一个ImageView,TextView ID
//                new int[]{R.id.img_shoukuan, R.id.txt_shoukuan});
//        //添加并且显示
//        gridView.setAdapter(saImageItems);
//        //添加消息处理
//        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                Toast.makeText(getActivity(),name[position],Toast.LENGTH_LONG).show();
//            }
        });
        gridView.setAdapter(adapter);

    }

//    public void loadImage(View view) {
//        Glide.with(this)
//                .load("http://guolin.tech/book.png")
//                .into(simpleTarget);
//    }
 private void gethomeicon() {
//    String id = listmusic.get(position).getSong_id();
//    final String pic =listmusic.get(position).getPic_big();
//    final String du = listmusic.get(position).getduration();
//    final String title =listmusic.get(position).getTitle();

    SynHttp.getInstance().getApi(baseURL, iapi.class).gethomeicon()
            .compose(SynSchedulersTranfs.<MyhomeIconBean>schedulersTransformer())
            .subscribe(new AbsRxSubscriber<MyhomeIconBean>() {
                @Override
                public void onRxError(ApiException ex) {
                    SynLog.file(ex.getDisplayMessage());
                }

                public void onNext(MyhomeIconBean myhomeIconBean) {

                    try {
                    List<MyhomeIconBean.DataBean> list = new ArrayList<MyhomeIconBean.DataBean>();
                    if((myhomeIconBean.getCode()+"").equalsIgnoreCase("200"))
                    {
                        list = myhomeIconBean.getData();
                    }
                    final String[] title = new String[10];
                    final String[] picurl = new String[10];
                    for (int i = 0;i<list.size();i++) {
                        if (i < 11) {
                            title[i] = list.get(i).getTitle();
                            picurl[i] = list.get(i).getCover();
                        }
                    }
                        title[9] = "http://cdn1.hkrstore.com/topics/10192018/jnfsunvekgoq.png";
                        picurl[9] = "全部";
                        adapter.addHeader(new RecyclerArrayAdapter.ItemView() {

                            GridView gridView;
                            @Override
                            public View onCreateView(ViewGroup parent) {
                                return LayoutInflater.from(activity).inflate(R.layout.head_audio_button, parent, false);
                            }

                            @Override
                            public void onBindView(View headerView) {
                                GridView gridView;
                                gridView = (GridView)headerView.findViewById(R.id.gridview_gn);
                                intview(gridView,title,picurl);
                            }
                        });
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                    SynLog.file("String----->" + myhomeIconBean.toString());
                }
            });
}

//猜你喜欢
    private void initHeaderTitle() {
        adapter.addHeader(new RecyclerArrayAdapter.ItemView() {
            @Override
            public View onCreateView(ViewGroup parent) {
                return LayoutInflater.from(activity).inflate(R.layout.head_audio_title, parent, false);
            }

            @Override
            public void onBindView(View headerView) {
                LinearLayout llChange = (LinearLayout) headerView.findViewById(R.id.ll_change);
                final ImageView ivChange = (ImageView) headerView.findViewById(R.id.iv_change);
                llChange.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startPropertyAnim(ivChange);
                    }
                });
            }
        });
    }

//列表
    private void initVideoContentView() {
        adapter.addHeader(new RecyclerArrayAdapter.ItemView() {
            @Override
            public View onCreateView(ViewGroup parent) {
                return LayoutInflater.from(activity).inflate(R.layout.head_audio_news, parent, false);
            }

            @Override
            public void onBindView(View headerView) {

            }
        });
    }

//猜你喜欢
    private void initFooterTitle() {
        adapter.addFooter(new RecyclerArrayAdapter.ItemView() {
            @Override
            public View onCreateView(ViewGroup parent) {
                return LayoutInflater.from(activity).inflate(R.layout.head_audio_title, parent, false);
            }

            @Override
            public void onBindView(View headerView) {
                TextView tvTitle = (TextView) headerView.findViewById(R.id.tv_title);
                LinearLayout llChange = (LinearLayout) headerView.findViewById(R.id.ll_change);
                final ImageView ivChange = (ImageView) headerView.findViewById(R.id.iv_change);

                tvTitle.setText("猜你喜欢");
                llChange.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startPropertyAnim(ivChange);
                    }
                });
            }
        });
    }


    private void initHorizontalView(final List<myhomemaibean.DataBean.ResourcesBean> data) {
        adapter.addFooter(new RecyclerArrayAdapter.ItemView() {
            @Override
            public View onCreateView(ViewGroup parent) {
                RecyclerView recyclerView = new RecyclerView(parent.getContext()){
                    //为了不打扰RecyclerView的滑动操作，可以这样处理
                    @SuppressLint("ClickableViewAccessibility")
                    @Override
                    public boolean onTouchEvent(MotionEvent event) {
                        super.onTouchEvent(event);
                        return true;
                    }
                };
                RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                layoutParams.setMargins(SizeUtils.dp2px(10),SizeUtils.dp2px(5),
                        SizeUtils.dp2px(10),SizeUtils.dp2px(10));
                recyclerView.setLayoutParams(layoutParams);
                final NarrowImageAdapter narrowAdapter;
                recyclerView.setAdapter(narrowAdapter = new NarrowImageAdapter(parent.getContext()));
                recyclerView.setLayoutManager(new LinearLayoutManager(parent.getContext(), LinearLayoutManager.HORIZONTAL,false));
                recyclerView.addItemDecoration(new SpaceViewItemLine(SizeUtils.dp2px(8)));
//加载更多
//                narrowAdapter.setMore(R.layout.view_more_horizontal, new RecyclerArrayAdapter.OnLoadMoreListener() {
//                    @Override
//                    public void onLoadMore() {
//                        new Handler().postDelayed(new Runnable() {
//                            @Override
//                            public void run() {
//                                ToastUtil.showToast(activity,"没有更多呢！");
//                            }
//                        },1000);
//                    }
//                });

//
                List<VideoPlayerFavorite> favoriteList = new ArrayList<VideoPlayerFavorite>();
                for(int a=0 ; a<data.size() ; a++){
                    VideoPlayerFavorite videoPlayerFavorite = new VideoPlayerFavorite(
                            data.get(a).getTitle(),data.get(a).getCover(),"");
                    favoriteList.add(videoPlayerFavorite);

                }

//               data
                narrowAdapter.addAll(favoriteList);
                return recyclerView;
            }

            @Override
            public void onBindView(View headerView) {
                //这里的处理别忘了
                ((ViewGroup)headerView).requestDisallowInterceptTouchEvent(true);
            }
        });
    }


    private void startPropertyAnim(ImageView ivChange) {
        // 第二个参数"rotation"表明要执行旋转
        // 0f -> 360f，从旋转360度，也可以是负值，负值即为逆时针旋转，正值是顺时针旋转。
        ObjectAnimator anim = ObjectAnimator.ofFloat(ivChange, "rotation", 0f, 360f);
        anim.setDuration(800);
        anim.start();
    }


}
